﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ykglxt
{
    public partial class Form_Main : Form
    {
        public Form_Main()
        {
            InitializeComponent();
        }

        private void Form_Main_Load(object sender, EventArgs e)
        {
            this.IsMdiContainer = true;
            this.Visible = false;
            Form_Login Login = new Form_Login();
            if (Login.ShowDialog() == DialogResult.OK)
            {
                if (Login.sIsAdmin == "是")
                    this.toolStrip管理员菜单.Visible = true;
                Login.Close();
                this.Visible = true;
                this.Show();
            }
            tsslRY.Text = "操作人：" + PublicUnit.UserName;
            try
            {
                using(SqlConnection con=new SqlConnection(PublicUnit.ConnetionString))
                {
                    con.Open();
                    SqlCommand com = new SqlCommand("SELECT * FROM Dic_KS WHERE BM = '" + PublicUnit.UserKSBM+"'",con);
                    SqlDataReader sdr = com.ExecuteReader();
                    if (sdr.Read())
                        tsslKS.Text = "登陆科室：" + sdr["MC"].ToString();
                    sdr.Close();
                    con.Close();
                }
            }
            catch(SqlException)
            {
                MessageBox.Show("网络故障，请稍后再试！","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                Application.Exit();
            }
        }

        void SetForm(Form formStyle)
        {
            formStyle.Height = this.ClientSize.Height;
            formStyle.Width = this.ClientSize.Width;
            formStyle.StartPosition = FormStartPosition.Manual;
            formStyle.MdiParent = this;
            formStyle.Show();
        }

        bool OpenOnce(Form frm)
        {
            foreach (Form mdifrm in this.MdiChildren)
            {
                if (frm.Text == mdifrm.Text)
                {
                    mdifrm.Activate();
                    return false;
                }
            }
            return true;
        } 

        private void 采购计划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_CGJH CGJH = new Form_CGJH();
            if (OpenOnce(CGJH) == true) 
            {
                SetForm(CGJH);
            }
        }

        private void 药品入库ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            Form_YPRK YPRK = new Form_YPRK();
            if (OpenOnce(YPRK) == true) 
            {
                SetForm(YPRK);
            }
        }

        private void 药品出库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
             Form_YPCK YPCK = new Form_YPCK();
             if (OpenOnce(YPCK) == true) 
            {
                SetForm(YPCK);
            }
        }

        private void 库存盘点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_KCPD KCPD = new Form_KCPD();
            if (OpenOnce(KCPD) == true) 
            {
                SetForm(KCPD);
            }
        }

        private void 发票登记与核销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_FPDJYHX FPDJYHX = new Form_FPDJYHX();
            if (OpenOnce(FPDJYHX) == true) 
            {
                SetForm(FPDJYHX);
            }
        }

        private void 药品入账凭证ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPRZPZ YPRZPZ = new Form_YPRZPZ();
            if (OpenOnce(YPRZPZ) == true) 
            {
                SetForm(YPRZPZ);
            }
        }

        private void 应付款查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YFKCX YFKCX = new Form_YFKCX();
            if (OpenOnce(YFKCX) == true) 
            {
                SetForm(YFKCX);
            }
        }

        private void 结账ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_JZ JZ = new Form_JZ();
            if (OpenOnce(JZ) == true) 
            {
                SetForm(JZ);
            }
        }

        private void 药品属性设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPSXSZ YPSXSZ = new Form_YPSXSZ();
            if (OpenOnce(YPSXSZ) == true) 
            {
                SetForm(YPSXSZ);
            }
        }

        private void 药品库存预警ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPKCYJ YPKCYJ = new Form_YPKCYJ();
            if (OpenOnce(YPKCYJ) == true) 
            {
                SetForm(YPKCYJ);
            }
        }

        private void 药品有效期查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPYXQCX YPYXQCX = new Form_YPYXQCX();
            if (OpenOnce(YPYXQCX) == true) 
            {
                SetForm(YPYXQCX);
            }
        }

        private void 药品采购价格分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPCGJGFX YPCGJGFX = new Form_YPCGJGFX();
            if (OpenOnce(YPCGJGFX) == true) 
            {
                SetForm(YPCGJGFX);
            }
        }

        private void 药品调价ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPTJ YPTJ = new Form_YPTJ();
            if (OpenOnce(YPTJ) == true) 
            {
                SetForm(YPTJ);
            }
        }

        private void 药品生产商对照ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPSCSDZ YPSCSDZ = new Form_YPSCSDZ();
            if (OpenOnce(YPSCSDZ) == true) 
            {
                SetForm(YPSCSDZ);
            }
        }

        private void 药品采购单查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPCGDCX YPCGDCX = new Form_YPCGDCX();
            if (OpenOnce(YPCGDCX) == true) 
            {
                SetForm(YPCGDCX);
            }
        }

        private void 药品入库单查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPRKDCX YPRKDCX = new Form_YPRKDCX();
            if (OpenOnce(YPRKDCX) == true) 
            {
                SetForm(YPRKDCX);
            }
        }

        private void 药品出库单查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPCKDCX YPCKDCX = new Form_YPCKDCX();
            if (OpenOnce(YPCKDCX) == true) 
            {
                SetForm(YPCKDCX);
            }
        }

        private void 药品出入明细查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPCRMXCX YPCRMXCX = new Form_YPCRMXCX();
            if (OpenOnce(YPCRMXCX) == true) 
            {
                SetForm(YPCRMXCX);
            }
        }

        private void 药品出入明细总账ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPCRMXZZ YPCRMXZZ = new Form_YPCRMXZZ();
            if (OpenOnce(YPCRMXZZ) == true) 
            {
                SetForm(YPCRMXZZ);
            }
        }

        private void 药品出入统计ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPCRTJ YPCRTJ = new Form_YPCRTJ();
            if (OpenOnce(YPCRTJ) == true) 
            {
                SetForm(YPCRTJ);
            }
        }

        private void 入库统计分析ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form_RKTJFX RKTJFX = new Form_RKTJFX();
            if (OpenOnce(RKTJFX) == true) 
            {
                SetForm(RKTJFX);
            }
        }

        private void 出库统计分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_CKTJFX CKTJFX = new Form_CKTJFX();
            if (OpenOnce(CKTJFX) == true) 
            {
                SetForm(CKTJFX);
            }
        }

        private void 药品出库排名查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPCKPMCX YPCKPMCX = new Form_YPCKPMCX();
            if (OpenOnce(YPCKPMCX) == true) 
            {
                SetForm(YPCKPMCX);
            }
        }

        private void 药价查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YJCX YJCX = new Form_YJCX();
            if (OpenOnce(YJCX) == true) 
            {
                SetForm(YJCX);
            }
        }

        private void 药品购入汇总表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPGRHZB YPGRHZB = new Form_YPGRHZB();
            if (OpenOnce(YPGRHZB) == true) 
            {
                SetForm(YPGRHZB);
            }
        }

        private void 出入库类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_CRKLX CRKLX = new Form_CRKLX();
            if (OpenOnce(CRKLX) == true) 
            {
                SetForm(CRKLX);
            }
        }

        private void 药品货位ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPHW YPHW = new Form_YPHW();
            if (OpenOnce(YPHW) == true) 
            {
                SetForm(YPHW);
            }
        }

        private void 药品供应商ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPGYS YPGYS = new Form_YPGYS();
            if (OpenOnce(YPGYS) == true) 
            {
                SetForm(YPGYS);
            }
        }

        private void 药品生产商ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPSCS YPSCS = new Form_YPSCS();
            if (OpenOnce(YPSCS) == true) 
            {
                SetForm(YPSCS);
            }
        }

        private void 药品批准文号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPPZWH YPPZWH = new Form_YPPZWH();
            if (OpenOnce(YPPZWH) == true) 
            {
                SetForm(YPPZWH);
            }
        }

        private void 药品类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPLB YPLX = new Form_YPLB();
            if (OpenOnce(YPLX) == true) 
            {
                SetForm(YPLX);
            }
        }

        private void 药品剂型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPJX YPJX = new Form_YPJX();
            if (OpenOnce(YPJX) == true) 
            {
                SetForm(YPJX);
            }
        }

        private void 药品统计类别ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPTJLB YPTJLB = new Form_YPTJLB();
            if (OpenOnce(YPTJLB) == true) 
            {
                SetForm(YPTJLB);
            }
        }

        private void 药品编码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPBM YPBM = new Form_YPBM();
            if (OpenOnce(YPBM) == true) 
            {
                SetForm(YPBM);
            }
        }

        private void 药品用法ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPYF YPYF = new Form_YPYF();
            if (OpenOnce(YPYF) == true) 
            {
                SetForm(YPYF);
            }
        }

        private void 药品使用次数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_YPSYCS YPSYCS = new Form_YPSYCS();
            if (OpenOnce(YPSYCS) == true) 
            {
                SetForm(YPSYCS);
            }
        }

        private void 参数设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_CSSZ CSSZ = new Form_CSSZ();
            if (OpenOnce(CSSZ) == true) 
            {
                SetForm(CSSZ);
            }
        }

        private void 密码修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
                Form_MMXG MMXG = new Form_MMXG();
                MMXG.ShowDialog();
        }

        private void 重新登陆ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Form_Login Login = new Form_Login();
            if(Login.ShowDialog()==DialogResult.OK)
            {
                this.toolStrip管理员菜单.Visible = false;
                if (Login.sIsAdmin == "是")
                    this.toolStrip管理员菜单.Visible = true;
                Login.Close();
                tsslRY.Text = "操作人：" + PublicUnit.UserName;
                try
                {
                    using(SqlConnection con=new SqlConnection(PublicUnit.ConnetionString))
                    {
                        con.Open();
                        SqlCommand com = new SqlCommand("SELECT * FROM Dic_KS WHERE BM = '" + PublicUnit.UserKSBM+"'",con);
                        SqlDataReader sdr = com.ExecuteReader();
                        if (sdr.Read())
                            tsslKS.Text = "登陆科室：" + sdr["MC"].ToString();
                        sdr.Close();
                        con.Close();
                    }
                }
                catch(SqlException)
                {
                    MessageBox.Show("网络故障，请稍后再试！","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                    Application.Exit();
                }
            }
        }

        private void 退出系统ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show(this,"确认退出？","警告",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning)==DialogResult.OK)
                this.Close();
        }

        private void 计算器toolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc.exe");
        }

        private void timerSJ_Tick(object sender, EventArgs e)
        {
            tsslSJ.Text = "时间：" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); 
        }

        private void 科室字典ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_KSZD KSZD = new Form_KSZD();
            if (OpenOnce(KSZD) == true)
            {
                SetForm(KSZD);
            }
        }

        private void 费别字典ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_FBZD FBZD = new Form_FBZD();
            if (OpenOnce(FBZD) == true)
            {
                SetForm(FBZD);
            }
        }

        private void 人员字典ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form_RYZD RYZD = new Form_RYZD();
            if (OpenOnce(RYZD) == true)
            {
                SetForm(RYZD);
            }

        }

    }
}
